/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package su.samlib.informer.database.model;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author rikland
 */
@Entity
@Table(name = "book")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Book.findAll", query = "SELECT b FROM Book b"),
    @NamedQuery(name = "Book.findByBookId", query = "SELECT b FROM Book b WHERE b.bookId = :bookId"),
    @NamedQuery(name = "Book.findByBookTitle", query = "SELECT b FROM Book b WHERE b.bookTitle = :bookTitle"),
    @NamedQuery(name = "Book.findByBookUri", query = "SELECT b FROM Book b WHERE b.bookUri = :bookUri"),
    @NamedQuery(name = "Book.findByBookDescription", query = "SELECT b FROM Book b WHERE b.bookDescription = :bookDescription"),
    @NamedQuery(name = "Book.findByBookText", query = "SELECT b FROM Book b WHERE b.bookText = :bookText"),
    @NamedQuery(name = "Book.findByBookSize", query = "SELECT b FROM Book b WHERE b.bookSize = :bookSize"),
    @NamedQuery(name = "Book.findByBookUpdateDate", query = "SELECT b FROM Book b WHERE b.bookUpdateDate = :bookUpdateDate")})
public class Book implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "book_id", nullable = false)
//    @GeneratedValue(generator="book_book_id_seq")
//    @SequenceGenerator(name="book_book_id_seq",sequenceName="book_book_id_seq",allocationSize=1)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer bookId;
    @Column(name = "book_title", length = 250)
    private String bookTitle;
    @Basic(optional = false)
    @Column(name = "book_uri", nullable = false, length = 150)
    private String bookUri;
    @Column(name = "book_description")//, length = 2147483647)
    private String bookDescription;
    @Column(name = "book_text")//, length = 2147483647)
    private String bookText;
    @Column(name = "book_size")
    private BigInteger bookSize;
    @Column(name = "book_update_date")
    @Temporal(TemporalType.DATE)
    private Date bookUpdateDate;
    @JoinColumn(name = "author_id", referencedColumnName = "author_id", nullable = false)
    @ManyToOne(optional = false)
    private Author authorId;

    public Book() {
    }

    public Book(Integer bookId) {
        this.bookId = bookId;
    }

    public Book(Integer bookId, String bookUri) {
        this.bookId = bookId;
        this.bookUri = bookUri;
    }

    public Integer getBookId() {
        return bookId;
    }

    public void setBookId(Integer bookId) {
        this.bookId = bookId;
    }

    public String getBookTitle() {
        return bookTitle;
    }

    public void setBookTitle(String bookTitle) {
        this.bookTitle = bookTitle;
    }

    public String getBookUri() {
        return bookUri;
    }

    public void setBookUri(String bookUri) {
        this.bookUri = bookUri;
    }

    public String getBookDescription() {
        return bookDescription;
    }

    public void setBookDescription(String bookDescription) {
        this.bookDescription = bookDescription;
    }

    public String getBookText() {
        return bookText;
    }

    public void setBookText(String bookText) {
        this.bookText = bookText;
    }

    public BigInteger getBookSize() {
        return bookSize;
    }

    public void setBookSize(BigInteger bookSize) {
        this.bookSize = bookSize;
    }

    public Date getBookUpdateDate() {
        return bookUpdateDate;
    }

    public void setBookUpdateDate(Date bookUpdateDate) {
        this.bookUpdateDate = bookUpdateDate;
    }

    public Author getAuthorId() {
        return authorId;
    }

    public void setAuthorId(Author authorId) {
        this.authorId = authorId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (bookId != null ? bookId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Book)) {
            return false;
        }
        Book other = (Book) object;
        if ((this.bookId == null && other.bookId != null) || (this.bookId != null && !this.bookId.equals(other.bookId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "su.samlib.informer.database.model.Book[ bookId=" + bookId + " ]";
    }
    
}
